#include <iostream>
#include <map>
#include <utility>

int const inf = 100;
int l, r, ans;

std::map<std::pair<int, int>, int> vis;

int dfs(std::pair<int, int> const & x)
{
//	std::cout << x.first << ' ' << x.second << '\n';
	if (x.first < 0) return inf;
	if (x.first == 0) return x.second;
	if (x.second > ans) return inf;
	if (vis.find(x) != vis.end()) return vis[x];

	int l = x.first, r = x.second;
	int d = r - l;
	// left
	int min = dfs(std::make_pair(l, l + d*2 + 1));
	min = std::min(min, dfs(std::make_pair(l, l + d*2)));

	// right
	min = std::min(min, dfs(std::make_pair(r - 2*d - 1, r)));
	min = std::min(min, dfs(std::make_pair(r - 2*d, r)));
	if (min < ans) ans = min;
	return vis[x] = min;
}

int main()
{
	std::ios::sync_with_stdio(false);
	while (std::cin >> l >> r) {
		ans = inf;
		vis.clear();
		int ans = dfs(std::make_pair(l, r));
		if (ans >= inf) ans = -1;
		std::cout << ans << '\n';
	}
}

